
#pragma once

#include <unistd.h>
#include <cstring>
#include <memory>
#include <unordered_map>
#include <vector>

#define EPOLL_CREATE_SIZE 128
#define EPOLL_WAIT_NUM 10

class Channel;
class EventLoop;

class Epoller {
public:
    // New:某个channel还没添加至Poller
    // Added:
    // Deleted:
    // enum channel_state { New = -1, Added, Deleted };
    Epoller(EventLoop* loop);

    int EpollCtl(Channel* channel, int op);

    void UpdateChannel(Channel* channel);
    void RemoveChannel(Channel* channel);

    void EpollWait(std::vector<Channel*>* active_channels, int flag = 0);

    ~Epoller();

private:
    int epfd_;
    std::vector<struct epoll_event> evs_;
    EventLoop* loop_;
    std::unordered_map<int, Channel*> channel_map_;
};
